﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EyFramework.Task.Excutor;

namespace EyFramework.Task
{
    /// <summary>
    /// 常量类
    /// </summary>
    public static class TaskConstants
    {
        public const string WINSERVER_REDIS_KEY = "XseyTask";
        public const string TASK_JOBDATAMAP_KEY = "taskInfo";
        public const string 任务状态_作废 = "0";
        public const string 任务状态_启用 = "1";

        public const string RUN_STATE_未启动 = "0";//0
        public const string RUN_STATE_运行中 = "1";//1
        public const string RUN_STATE_暂停 = "2";//2

        public const string TASK_COMMAND_启动 = "1";
        public const string TASK_COMMAND_暂停 = "2";
        public const string TASK_COMMAND_停止 = "3";
        public const string TASK_COMMAND_恢复 = "4";

        public const string 任务运行结果_成功 = "成功";
        public const string 任务运行结果_失败 = "失败";

        ////////////////////////////////
        /// 以下参数为JobDataMap的键 ///
        ////////////////////////////////

        //任务类型
        public const string TASK_TYPE = "TASK_TYPE";

        //任务组
        public const string TASK_GROUP = "TASK_GROUP";

        //任务名称
        public const string TASK_NAME = "TASK_NAME";

        //CRON时间表达式
        public const string CRON = "CRON";

        public const string 函数名 = "METHOD_NAME";
        public const string 类名 = "CLASS_NAME";
        public const string 文件名 = "FILE_NAME";

        public const string TASK_TYPE_METHOD = "1";
        public const string TASK_TYPE_HTTP = "2";
        public const string TASK_TYPE_SQL = "3";
        public const string TASK_TYPE_EXE = "4";

        public const string MESSAGE_TYPE_DD = "1";
        public const string MESSAGE_TYPE_EMAIL = "1";
        public static List<string> runningTask = new List<string>();

        public static IJobExecutor CreateExecutor(string pTaskType)
        {
            IJobExecutor executor = null;
            switch (pTaskType)
            {
                case "1":
                    executor = new CSharpJobExecutor();
                    break;

                case "2":
                    executor = new HttpJobExecutor();
                    break;

                case "3":
                    executor = new SqlJobExecutor();
                    break;

                case "4":
                    executor = new ExeJobExecutor();
                    break;
            }
            return executor;
        }
    }
}